﻿#include <QApplication>
#include <QFile>
#include <iostream>

#include "tablepdf.h"

using namespace std;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    std::string title("报告1");
    std::string userImg("1.png");
    std::string userName("张三");
    std::string csvFile("csvFile.csv");
#ifndef QT_DEBUG
    Q_ASSERT(argc == 5);
    if (argc != 5) {
        std::cout << "入参数错误！" << std::endl;
        return -1;
    }
    for (int i = 1; i < 5; ++i) {
        if (sizeof(argv[i]) == 0) {
            std::cout << "入参" << i << "为空！" << std::endl;
            return 1;
        }
    }

    title = argv[1];
    userImg = argv[2];
    userName = argv[3];
    csvFile = argv[4];
#endif // QT_DEBUG

    // 检查用户水印文件
    if (!QFile::exists(QString::fromStdString(userImg))) {
        std::cout << "用户水印不存在！" << std::endl;
        return 2;
    }

    // 检查CSV文件
    if (!QFile::exists(QString::fromStdString(csvFile))) {
        std::cout << "数据源表不存在！" << std::endl;
        return 3;
    }

    TablePdf myPdf;
    myPdf.setPassword("grdlog1902464434", NULL);
    HPDF_UINT permission = HPDF_ENABLE_READ | HPDF_ENABLE_PRINT;
    myPdf.SetPermission(permission);
    myPdf.setPageMargin(40, 40, 30, 30);
    myPdf.addTitle(title, userName);
    if (!myPdf.getTableCsv(csvFile.c_str())) {
        std::cout << "读取数据失败！" << std::endl;
        return 4;
    }
    myPdf.watermarkDraw(userImg, 0.3);
    myPdf.drawTable();
    myPdf.savePdf(csvFile);

    return 0;
}
